#!/usr/bin/env python
# -*- coding:utf-8 -*-
import io

from rich import print
from rich.table import Table
from rich.console import Console
from rich.text import Text

# grid = Table.grid(expand=True)
# grid.add_column()
# grid.add_column(justify="right")
# grid.add_row("Raising shields", "[bold magenta]COMPLETED [green]:heavy_check_mark:")
#
# print(grid)
console = Console(
    width=60,
    force_terminal=True,
    file=io.StringIO(),
    legacy_windows=False,
    color_system=None,
)

table = Table(title="test table", caption="table caption", expand=True)
table.add_column("foo", footer=Text("total"), no_wrap=True, overflow="ellipsis")
table.add_column("bar", justify="center")
table.add_column("baz", justify="right")

table.add_row("Averlongwordgoeshere", "banana pancakes", None)

# assert Measurement.get(console, table, 80) == Measurement(41, 48)

for width in range(10, 60, 5):
    console.print(table, width=width)

table.expand = False
console.print(table, justify="left")
console.print(table, justify="center")
console.print(table, justify="right")

assert table.row_count == 1

table.row_styles = ["red", "yellow"]
table.add_row("Coffee")
table.add_row("Coffee", "Chocolate", None, "cinnamon")

assert table.row_count == 3

console.print(table)
print(table)